package com.sikao.app.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sikao.app.R;
import com.sikao.app.bean.MyAuctionRecordBean;
import com.sikao.app.utils.TimeUtil;

import java.util.List;

/**
 * Created by Administrator on 2016/8/10.
 */
public class MyAuctionRecordAdapter extends BaseAdapter {

	private Context context;
	private List<MyAuctionRecordBean.ResBean.ListBean> beans;

	public MyAuctionRecordAdapter(Context context, List<MyAuctionRecordBean.ResBean.ListBean> beans) {
		this.context = context;
		this.beans = beans;
	}

	@Override
	public int getCount() {
		return beans.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view;
		ViewHolder viewHolder;
		if (convertView == null) {
			view = View.inflate(context, R.layout.my_auction_record_list_item, null);
			viewHolder = new ViewHolder(view);
			view.setTag(viewHolder);
		} else {
			view = convertView;
			viewHolder = (ViewHolder) view.getTag();
		}
		if (position == 0) {
			viewHolder.view.setVisibility(View.VISIBLE);
			viewHolder.view1.setVisibility(View.GONE);
		} else {
			viewHolder.view.setVisibility(View.GONE);
			viewHolder.view1.setVisibility(View.VISIBLE);
		}
		viewHolder.tvname.setText(beans.get(position).getTitle());
		viewHolder.tvtime.setText(TimeUtil.timeStampToTime(beans.get(position).getAdd_time(), TimeUtil.fotmatString2));
		viewHolder.tvmoney.setText(beans.get(position).getTotal_amount());
		return view;
	}

	public class ViewHolder {
		public final View view;
		public final View view1;
		public final TextView tvname;
		public final TextView tvtime;
		public final TextView tvmoney;
		public final View root;

		public ViewHolder(View root) {
			view = root.findViewById(R.id.view);
			view1 = root.findViewById(R.id.view1);
			tvname = (TextView) root.findViewById(R.id.tv_name);
			tvtime = (TextView) root.findViewById(R.id.tv_time);
			tvmoney = (TextView) root.findViewById(R.id.tv_money);
			this.root = root;
		}
	}
}
